package com.studerb.old;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.studerb.dao.ServerDao;
import com.studerb.model.Server;
import com.studerb.util.Util;

public class TestServerDao {

	private static ServerDao serverDao;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		Util.startServices();
		serverDao = new ServerDao();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		Util.stopServices();
		serverDao = null;
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAdd() {
		Server server = new Server("news.giganews.com", new Integer(119), new Integer(9), "user",
				"password", false, true);
		Server savedServer;
		try {
			// save a serverh
			serverDao.getHibernateTemplate().save(server);
			serverDao.getHibernateTemplate().flush();
			serverDao.getHibernateTemplate().clear();
			// get the saved server
			savedServer = (Server) serverDao.getHibernateTemplate().get(Server.class,
					server.getId());
			assertEquals(server.getHost(), savedServer.getHost());
		} catch (Exception e) {
			e.printStackTrace();
			fail("Should not have caught exception in testAddServer..." + e.getMessage());
			
		}
	}
}
